package org.shiwen.week12;

import java.util.StringTokenizer;

public class StringTokenizer1 {
    public static void main(String[] args) {
        String a = "hello,world,java,program.aaa,sss";
        StringTokenizer st = new StringTokenizer(a,",");
//        StringTokenizer st = new StringTokenizer(a,", .");
        // 创建一个StringTokenizer对象
        // 参数一为字符串，参数二为分隔符
        System.out.println(st.countTokens());
        //你可以用countTokens方法来获取有多少个分隔符
        while(st.hasMoreTokens()){
            System.out.println(st.nextToken());
        }
        //用hasMoreTokens方法来判断是否还有下一个分隔符，来实现输出单词的效果
    }
}
